package com.luych.toolbox.docker.service.sdk.network;

import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworksCreateParam;
import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworksCreateResult;
import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworksPruneResult;
import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworksResult;
import org.springframework.web.client.RestTemplate;

public class DockerNetworks {

    private final String url;

    public DockerNetworks(String url) {
        this.url = url;
    }

    public DockerNetwork network(String id) {
        return new DockerNetwork(url, id);
    }

    public DockerNetworksResult all() {
        final String uri = url + "/networks";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerNetworksResult.class);
    }

    public DockerNetworksCreateResult create(DockerNetworksCreateParam param) {
        final String uri = url + "/networks/create";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForObject(uri, param, DockerNetworksCreateResult.class);
    }

    public DockerNetworksPruneResult prune() {
        final String uri = url + "/networks/prune";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForObject(uri, null, DockerNetworksPruneResult.class);
    }
}

